// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
/* Copyright (c) 2011 Team A CS2340. All rights reserved.*/

package edu.gatech.teama.doctorsoffice.client.presenter;


import java.util.List;

import javax.swing.JLabel;

import edu.gatech.teama.doctorsoffice.client.view.AppointmentRequestPanel;

import edu.gatech.teama.doctorsoffice.client.view.LoginPanel;
import edu.gatech.teama.doctorsoffice.client.view.MainWindow;
import edu.gatech.teama.doctorsoffice.model.*; // $codepro.audit.disable importStyle

/**
 * PatientMainPresenter.java 
 * @author - author name
 * @version 1.0
 */
public class PatientMainPresenter {
	/**
	 * server connection sc
	 */
	private final ServerConnection sc;

	/**
	 * logged user
	 */
	private User loggedUser;
	
	/**
	 * Patient Main Presenter constructor
	 */
	public PatientMainPresenter() {
		sc = ServerConnection.getInstance();
		loggedUser=sc.getLoggedInUser();
	}
	
	/**
	 * tests whether is a patient
	 * @return is the user a doctor or nurse
	 */
	public boolean isPatient() {
		return (loggedUser instanceof Patient);
	}
	
	/**
	 * gets logged user
	 * @return the logged in user
	 */
	public User getLoggedUser() {
		return loggedUser;
	}
	
	/**
	 * sets logged user
	 * @param u
	 */
	public void setLoggedUser(User u) {
		loggedUser=u;
	}
	
	/**
	 * set jLabel areas
	 * @param name
	 */
	public void setPersonalInfo(JLabel name) {
		name.setText("hhaah");
	}

	/**
	 * log out
	 */
	public void logout() {
		loggedUser=null;
		sc.disconnect();
		MainWindow.setPanel(new LoginPanel());
		
	}

	/**
	 * request appointment
	 */
	public void requestApt() {
		MainWindow.setPanel(new AppointmentRequestPanel());
		MainWindow.getFrame().pack();
		
	}
	
	/**
	 * Returns a list of appointments for a user
	 * @return a list of appointments for the user
	 */
	public List<Appointment> getAppointments() {
		return sc.getAppointmentForUser(sc.getLoggedInUser().getUsername());
	}
}
